<?php
/**
 * Created by PhpStorm.
 * User: jwb
 * Date: 2021/5/7
 * Time: 9:38
 */

namespace App\Inventor\Controllers;


use App\Http\Controllers\Controller;
use App\Repositories\PatentRepository;
use App\Services\PatentEstimateService;
use Dompdf\Dompdf;
use Encore\Admin\Layout\Content;

class EstimateController extends Controller
{
    public $repository;
    protected $service;

    public function __construct(PatentRepository $repository, PatentEstimateService $service)
    {
        $this->repository = $repository;
        $this->service = $service;
    }

    public function index(Content $content)
    {
        $grid = $this->repository->userGrid();
        return $content
            ->title('分级分类')
            ->description('')
            ->body($this->service->gridColumn($grid));
    }

    public function show($id)
    {
        $patent = $this->repository->find($id);
        return $this->service->showHtml($patent);
    }

    public function pdf($id)
    {
//        return view('test');
        $patent = $this->repository->find($id);
        $dompdf = new Dompdf();
        $dompdf->loadHtml($this->service->showHtml($patent));
        //$dompdf->loadHtml(view('test'));
        $dompdf->render();
        $dompdf->stream('bbbb.pdf');
    }
}
